home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cug124.arc / CEDIT.C < prev    next >
Text File  |  1986-02-14  |  8KB  |  351 lines

  1. #include    BDSCIO.H
  2.  
  3. /**************************************************************/
  4. /* TITLE: CEDIT Utility (Epson MX80 version)              */
  5. /*                                  */
  6. /* ID: CEDIT        Version 1.1        30th January 1983          */
  7. /*                                  */
  8. /* PROGRAMMER:  Paolo Prandini                      */
  9. /*        Viale Europa 72/G                  */
  10. /*        25100 Brescia -- Italy                  */
  11. /*                                  */
  12. /* DESCRIPTION:    In any Epson MX80/III or Epson MX80 with Graf-*/
  13. /*        trax we can easily notice the presence of 3   */
  14. /*        2716-type EPROMS. The central one contains the*/
  15. /*        character patterns of the main set and also of*/
  16. /*        the national sets: the content of this EPROM  */
  17. /*        is reproduced in the MASTER.CHR file (Please  */
  18. /*        note that from now on we'll refer to every    */
  19. /*        character set file as .CHR, that is the defau-*/
  20. /*        lt forced specification for this type of file)*/
  21. /*        With this program anyone can easily edit his  */
  22. /*        own set (even APL!): a scholar used it to de- */
  23. /*        fine an old Indian language for his Softcard  */
  24. /*        Apple CP/M system!                  */
  25. /*        The edited char set can be saved to disk and  */
  26. /*        later programmed onto a new 2716 EPROM with   */
  27. /*        any suitable hardware ( I used an homebrew    */
  28. /*        programmer ).                      */
  29. /*        COMMANDS AVAILABLE:                  */
  30. /*    X    .E(X)it and reboot CP/M                  */
  31. /*    E    .(E)dit current char pattern              */
  32. /*        The cursor positions on the upper left corner */
  33. /*        of the character screen area and then the fol-*/
  34. /*        lowing control sequences are accepted:          */
  35. /*        ^S,^H    moves cursor left              */
  36. /*        ^D    moves cursor right              */
  37. /*        ^X    moves cursor down              */
  38. /*        ^E    moves cursor up                  */
  39. /*        Space    clears current dot and moves right    */
  40. /*        0    sets current dot and moves right      */
  41. /*        ^Q    exits edit mode and saves edited char */
  42. /*        ESC    exits edit mode without saving modifi-*/
  43. /*            ed character                  */
  44. /*    C    .(C)hange current char waiting for any char   */
  45. /*    N    .Change current char waiting for a two digit  */
  46. /*        hexadecimal (N)umeric value              */
  47. /*    F    .Change current default (F)ile name          */
  48. /*    L    .(L)oad char set file using default file name */
  49. /*    S    .(S)ave char set file using default file name */
  50. /*                                  */
  51. /* HISTORY:    Cursor addressing sequences for ADM 3A          */
  52. /*                                  */
  53. /**************************************************************/
  54.  
  55. #define    COLUMN    9    /* Character matrix width and length  */
  56. #define    ROW    8    /* for EPSON MX80              */
  57.  
  58. char    matrix[COLUMN][ROW],caract;
  59. char    file_in[32],filename[32],work_file[32];
  60. int    yes_file,yes_exit;
  61.  
  62. main(argc,argv)
  63. int    argc;
  64. char    **argv;
  65. {
  66.     int    i,j;
  67.     char    c;
  68.     yes_file=FALSE;
  69.     yes_exit=FALSE;
  70.     if (argc>2) {  /* If more than 2 parms then error */
  71.         printf("Use:  CEDIT  charset.CHR\n");
  72.         exit();
  73.     }
  74.     printf(CLEARS); /* Clear screen */
  75.     caract=' ';
  76.     status_line();
  77.     if (argc==2) { /* Get work char set file */
  78.         for (i=0;(c=argv[1][i]) && c!='.';i++)
  79.             file_in[i]=c;
  80.         file_in[i]='\0';
  81.         strcat(file_in,".CHR"); /* Force .CHR */
  82.         strcpy(filename,file_in);
  83.         if ((open_in(file_in))==OK)
  84.             status_line();
  85.     }
  86.  
  87.     /* Initialize current char matrix */
  88.     for (i=1;i<=COLUMN;++i) for (j=1;j<=ROW;++j) matrix[i][j]=0;
  89.  
  90.     caract=' ';
  91.     while (yes_exit==FALSE) {
  92.         if (yes_file==TRUE) {
  93.             get_matrix(area());
  94.             out_matrix();
  95.         }
  96.         get_input();
  97.         status_line();
  98.     }
  99. }
  100.  
  101. edit_matrix()
  102. {
  103.     char    cm;
  104.     int    x,y,txit;
  105.     cm=0;
  106.     x=35;
  107.     y=8;
  108.     setcursor(x,y);
  109.     txit=FALSE;
  110.     while (txit==FALSE) {
  111.         cm=inkey();
  112.         switch(cm) {
  113.         case 24:    
  114.             ++y;
  115.             if (y>7+ROW) y=7+ROW;
  116.             break;
  117.         case 05:    
  118.             --y;
  119.             if (y<8) y=8;
  120.             break;
  121.         case 8:
  122.         case 19:    
  123.             --x;
  124.             if (x<35) x=35;
  125.             break;
  126.         case 04:    
  127.             ++x;
  128.             if (x>34+COLUMN) x=34+COLUMN;
  129.             break;
  130.         case 32:    
  131.             matrix[x-34][y-7]=1;
  132.             printf("%c",45-2*((x-34)-((x-34)/2)*2));
  133.             ++x;
  134.             if (x>34+COLUMN) x=34+COLUMN;
  135.             break;
  136.         case 48:    
  137.             matrix[x-34][y-7]=0;
  138.             printf("O");
  139.             ++x;
  140.             if (x>34+COLUMN) x=34+COLUMN;
  141.             break;
  142.         case 27:    
  143.             txit=TRUE;
  144.             break;
  145.         case 17:    
  146.             txit=TRUE;
  147.             put_matrix(area());
  148.             break;
  149.         default:    
  150.             putchar(7);
  151.         }
  152.         setcursor(x,y);
  153.     }
  154. }
  155.  
  156. inkey() /* Get single char without echo ! */
  157. {
  158.     return(bios(3,0));
  159. }
  160.  
  161.  
  162. status_line()
  163. {    
  164.     int    cm;
  165.     init_screen();
  166.     if ((caract<126) & (caract>31)) cm=caract;
  167.     else cm='.';
  168.     setcursor(0,0);
  169.     printf("CEDIT v1.1/Epson MX80   Work File:");
  170.     if (yes_file==TRUE) printf("%-26s",filename);
  171.     else printf("None                      ");
  172.     setcursor(50,0);
  173.     printf("Char %s%c%s  Value %s%-02x%s",
  174.     INTOREV,cm,OUTAREV,INTOREV,caract,OUTAREV);
  175. }
  176.  
  177. get_input()
  178. {    
  179.     char    opt,filenout[32],s;
  180.     int    value,j;
  181.     setcursor(0,22);
  182.     printf("-- X=Exit  E=Edit  C=Chan  F=File  L=Load  S=Save");
  183.     printf("  N=Numb  ---->            \b\b\b\b\b\b\b\b");
  184.     printf("\b\b\b\b");
  185.     opt=toupper(inkey());
  186.     switch(opt) {
  187.     case 'X':    
  188.         exit();
  189.         break;
  190.     case 'C':    
  191.         setcursor(56,0);
  192.         caract=inkey();
  193.         if (caract<32) caract=' ';
  194.         break;
  195.     case 'N':    
  196.         setcursor(67,0);
  197.         scanf("%x",&value);
  198.         if (value<32) caract=32;
  199.         else caract=value;
  200.         break;
  201.     case 'E':    
  202.         edit_matrix();
  203.         break;
  204.     case 'F':    
  205.         printf("_\b");
  206.         scanf("%s",filenout);
  207.         for (j=0;((s=filenout[j]) && s!='.') ||
  208.                         j>strlen(filenout);j++)
  209.                 work_file[j]=toupper(s);
  210.         work_file[j]='\0';
  211.         strcat(work_file,".CHR");
  212.         break;
  213.     case 'L':    
  214.         yes_file=FALSE;
  215.         strcpy(file_in,work_file);
  216.         open_in(file_in);
  217.         if (yes_file==TRUE)
  218.             strcpy(filename,work_file);
  219.         break;
  220.     case 'S':    
  221.         yes_file=FALSE;
  222.         strcpy(file_in,work_file);
  223.         open_out(file_in);
  224.         if (yes_file==TRUE)
  225.             strcpy(filename,work_file);
  226.         break;
  227.     default:    
  228.         putchar(7);
  229.     }
  230. }
  231.  
  232. area() /* Compute address of working char */
  233. {
  234.     int    s;
  235.     s=(endext()+100+(caract-32)*9);
  236.     setcursor(5,5);
  237.     s=s+4*((s-(endext()+100))>>8);
  238.     return(s);
  239. }
  240.  
  241. setcursor(x,y) /* Set cursor function , modify for your terminal */
  242. int    x,y;
  243. {
  244.     putchar(ESC);
  245.     putchar('=');
  246.     putchar(y+32);
  247.     putchar(x+32);
  248. }
  249.  
  250. open_in(file_in) /* Read workfile in memory at endext()+100 */
  251. char    file_in[32];
  252. {
  253.     int    n;
  254.     if ((n=open(file_in,0))==ERROR) {
  255.         setcursor(24,0);
  256.         printf("Can't open:%s",file_in);
  257.         return(ERROR);
  258.     }
  259.     if ((read(n,endext()+100,16))<16) {
  260.         setcursor(24,0);    
  261.         printf("Character set %s invalid",file_in);
  262.         return(ERROR);
  263.     }
  264.     close(n);
  265.     yes_file=TRUE;
  266.     return(OK);
  267. }
  268.  
  269. open_out(file_in) /* Write workfile present in memory from endext()+100 */
  270. char    file_in[32];
  271. {
  272.     int    n;
  273.     if ((n=creat(file_in))!=ERROR) {
  274.         write(n,endext()+100,16);
  275.         yes_file=TRUE;
  276.     } 
  277.     else {
  278.         setcursor(24,0);
  279.         printf("Can't create:%s",file_in);
  280.     }
  281.     close(n);
  282. }
  283.  
  284. int exp(n) /* Compute 2 raised to nth power */
  285. int    n;
  286. {
  287.     return(n ? (2*exp(--n)) : 1);
  288. }
  289.  
  290. get_matrix(pa) /* Load specified memory area into character matrix */
  291. char    *pa;
  292. {
  293.     char    cm;
  294.     char    scratch;
  295.     int    i,j;
  296.  
  297.     scratch=caract;
  298.     for (i=1;i<=COLUMN;++i) {
  299.         cm=*pa;
  300.         for (j=1;j<=ROW;++j)
  301.             matrix[i][j]=(cm & exp(8-j));
  302.         ++pa;
  303.     }
  304.     caract=scratch;
  305. }
  306.  
  307. put_matrix(pa) /* Write back character matrix to memory */
  308. char    *pa;
  309. {
  310.     char    cm,scratch;
  311.     int    i,j;
  312.  
  313.     scratch=caract;
  314.     for (i=1;i<=COLUMN;++i) {
  315.         cm=0;
  316.         for (j=1;j<=ROW;++j) {
  317.             if (matrix[i][j]!=0)
  318.                 cm=(cm | exp(8-j));
  319.         }
  320.         *pa=cm;
  321.         ++pa;
  322.     }
  323.     caract=scratch;
  324. }
  325.  
  326. init_screen()
  327. {
  328.     int    y;
  329.     for (y=7;y<17;y++) {
  330.         setcursor(33,y);
  331.         printf(INTOREV);
  332.         setcursor(45,y);
  333.         printf(OUTAREV);
  334.     }
  335. }
  336.  
  337. out_matrix() /* Print out character matrix */
  338. {
  339.     int    i,j,y;
  340.     y=8;
  341.     for (i=1;i<=ROW;++i) {
  342.         setcursor(35,y);
  343.         ++y;
  344.         for (j=1;j<=COLUMN;++j) {
  345.             if (matrix[j][i]==0) putchar('O');
  346.             else putchar(45-2*(j-(j/2)*2));
  347.         }
  348.     }
  349. }
  350.  
  351.